package com.lsq.baseadmin.modules.maintenance.controller;


import com.lsq.baseadmin.modules.maintenance.entity.Menu;
import com.lsq.baseadmin.modules.maintenance.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lsq
 * @since 2020-10-23
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    private MenuService menuService;

    public MenuController(MenuService menuService) {
        this.menuService = menuService;
    }

    @ApiOperation("菜单列表")
    @GetMapping("/list")
    public ResponseEntity list(Menu menu) {
        List<Menu> list = menuService.list(menu);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("菜单添加")
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody Menu menu) {
        menuService.save(menu);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("菜单修改")
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody Menu menu) {
        menuService.update(menu);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("菜单修改状态")
    @PostMapping("/updateStatus")
    public ResponseEntity updateStatus(@RequestBody Menu menu) {
        menuService.updateStatus(menu);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("菜单删除")
    @PostMapping("/delete")
    public ResponseEntity delete(int id) {
        menuService.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }

}
